package LCR;

public class reverse_linked {

    public ListNode reverseList(ListNode head) {
        if (head == null) {
            return head;
        }
        if (head.next == null) {
            return head;
        }
        ListNode cur = head.next;
        ListNode curNext = null;
        head.next = null;
        while (cur != null) {
            curNext = cur.next;
            cur.next = head;
            head = cur;
            cur = curNext;
        }
        return head;

    }

    public ListNode reverseList2(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode newhead = reverseList2(head.next);
        head.next.next = head;
        head.next = null;
        return newhead;
    }
}

